//
//  MororcadeTableCell.m
//  ICrEAM
//
//  Created by mac on 16/10/31.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "MororcadeTableCell.h"
#import "MorocadeButton.h"
@interface MororcadeTableCell()
@property (weak, nonatomic) IBOutlet UILabel *repairTypeL;
@property (weak, nonatomic) IBOutlet UILabel *comeInTimeL;
@property (weak, nonatomic) IBOutlet UIView *lisenceBgView;
@property (weak, nonatomic) IBOutlet UIView *repiarFirstView;
@property (weak, nonatomic) IBOutlet UILabel *repiarFirstDataL;
@property (weak, nonatomic) IBOutlet UILabel *repiarFirstDataDetail;

@property (weak, nonatomic) IBOutlet UIView *repairSecodeView;
@property (weak, nonatomic) IBOutlet UILabel *repiarSecodeDataL;
@property (weak, nonatomic) IBOutlet UILabel *repiarSecondeDataDetail;
@property (weak, nonatomic) IBOutlet UIButton *repairSecondeBtn;

@property (weak, nonatomic) IBOutlet UILabel *getCarTime;


@property (weak, nonatomic) IBOutlet UIButton *repairThirdBtn;



@property (weak, nonatomic) IBOutlet UIView *repairFourView;
@property (weak, nonatomic) IBOutlet UILabel *repairFourDate;
@property (weak, nonatomic) IBOutlet UILabel *repairFourDateDetail;


@property (weak, nonatomic) IBOutlet UIView *repairFiveView;
@property (weak, nonatomic) IBOutlet UILabel *repairFiveDateDetail;
@property (weak, nonatomic) IBOutlet UILabel *repairFiveDate;
@property (weak, nonatomic) IBOutlet MorocadeButton *repiarFiveBtn;


@property (weak, nonatomic) IBOutlet MorocadeButton *repairSixBtn;

@property (weak, nonatomic) IBOutlet UIView *repiarTypeView;

@property (weak, nonatomic) IBOutlet UILabel *licenseLable;
@property (weak, nonatomic) IBOutlet UILabel *liceseTimeL;

@end
@implementation MororcadeTableCell
+(instancetype)createMororcadeTableCell{
    return [[[NSBundle mainBundle]loadNibNamed:@"MororcadeTableCell" owner:nil options:nil]lastObject];
}
- (IBAction)repairTypeDetaulClick:(UIButton*)sender{
    CGAffineTransform transform=CGAffineTransformIdentity;
    
}
- (void)awakeFromNib {
    
    [super awakeFromNib];
    self.repairSecondeBtn.hidden=YES;
    self.repairThirdBtn.hidden=YES;
    self.repairSixBtn.hidden=YES;
    self.lisenceBgView.layer.cornerRadius=4;
    self.lisenceBgView.layer.masksToBounds=YES;
    self.selectionStyle=UITableViewCellSelectionStyleNone;
    self.lisenceBgView.backgroundColor=RGBA(30, 165, 255, 1);
    
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
//tag 1000开始
- (IBAction)repairBtnClick:(MorocadeButton *)sender {
    
    if (self.morocadeBlcok) {
        self.morocadeBlcok(self.type,self.mororcadeModel);
    }
}
-(void)setMororcadeModel:(MororcadeRespose *)mororcadeModel{
    _mororcadeModel=mororcadeModel;
    BOOL ispast=NO;
    if (mororcadeModel.apartDeliveryTime.length>2) {
        ispast=[[mororcadeModel.apartDeliveryTime substringWithRange:NSMakeRange(0, 2)] isEqualToString:@"超时"];
    }
    //是否超时
    if (ispast) {
        self.lisenceBgView.backgroundColor= RGB(251, 179, 35);
        self.getCarTime.textColor= RGB(251, 179, 35);
        
    }else{
        if ([ICrEAMTool isVW]) {
            self.lisenceBgView.backgroundColor= RGB(35, 193, 239);
        }else{
            self.lisenceBgView.backgroundColor= KSKBgColor;
        }
        
        self.getCarTime.textColor=[UIColor textColor];
    }
    self.getCarTime.text=mororcadeModel.apartDeliveryTime;
    //是否中断维修
    if (mororcadeModel.isStop) {
        self.lisenceBgView.backgroundColor= RGB(241, 111,100);
        [self.repairThirdBtn setImage:[UIImage imageNamed:@"repair_height_image"] forState:UIControlStateNormal];
    }else{
        [self.repairThirdBtn setImage:[UIImage imageNamed:@"repair_image"] forState:UIControlStateNormal];
    }
    self.liceseTimeL.text=mororcadeModel.deliveryDate;
    self.licenseLable.text=mororcadeModel.license;
    self.repairTypeL.text=mororcadeModel.repairTypeName;
    self.comeInTimeL.text=mororcadeModel.inWorkShopTime;
    //派工时间
    if (!IsStrEmpty(mororcadeModel.assignTime)) {
        self.repiarFirstView.hidden=NO;
        NSArray *arr1=[self getPrefixTime:mororcadeModel.assignTime];
        self.repiarFirstDataL.text=arr1[0];
        self.repiarFirstDataDetail.text=arr1[1];
    }else{
        self.repiarFirstView.hidden=YES;
    }
    //维修开始时间
    if (!IsStrEmpty(mororcadeModel.repairStartTime)) {
        self.repairSecodeView.hidden=NO;
        NSArray *arr1=[self getPrefixTime:mororcadeModel.repairStartTime];
        self.repiarSecodeDataL.text=arr1[0];
        self.repiarSecondeDataDetail.text=arr1[1];
    }else{
        self.repairSecodeView.hidden=YES;
    }
    //维修结束时间
    if (!IsStrEmpty(mororcadeModel.repairEndTime)) {
        self.repairFourView.hidden=NO;
        NSArray *arr1=[self getPrefixTime:mororcadeModel.repairEndTime];
        self.repairFourDate.text=arr1[0];
        self.repairFourDateDetail.text=arr1[1];
    }else{
        self.repairFourView.hidden=YES;
    }
    //质检时间
    if (!IsStrEmpty(mororcadeModel.qualityTestTime)) {
        self.repairFiveView.hidden=NO;
        NSArray *arr1=[self getPrefixTime:mororcadeModel.qualityTestTime];
        self.repairFiveDate.text=arr1[0];
        self.repairFiveDateDetail.text=arr1[1];
    }else{
        self.repairFiveView.hidden=YES;
    }
    switch ([mororcadeModel.repairStatus integerValue]) {
            //车的位置
        case 0:
            self.repairSecondeBtn.hidden=YES;
            self.repairThirdBtn.hidden=YES;
            self.repairSixBtn.hidden=YES;
            self.type=RepairStartType;
            break;
        case 1:
            self.repairSecondeBtn.hidden=NO;
            self.repairThirdBtn.hidden=YES;
            self.repairSixBtn.hidden=YES;
            self.repiarFiveBtn.hidden=YES;
            self.type=RepairStartType;
            break;
        case 2:
            self.repairSecondeBtn.hidden=YES;
            self.repairThirdBtn.hidden=NO;
            self.repairSixBtn.hidden=YES;
            self.repiarFiveBtn.hidden=YES;
            if (mororcadeModel.isStop) {
                self.type=RepairCancelType;
            }else{
                self.type=RepairProcedType;
            }
            break;
        case 3:
            self.repairSecondeBtn.hidden=YES;
            self.repairThirdBtn.hidden=YES;
            self.repairSixBtn.hidden=YES;
            self.repiarFiveBtn.hidden=NO;
            break;
        case 4:
            self.repairSecondeBtn.hidden=YES;
            self.repiarFiveBtn.hidden=YES;
            self.repairThirdBtn.hidden=YES;
            self.repairSixBtn.hidden=NO;
            break;
        default:
            break;
    }
    
    self.repairSecondeBtn.alpha=mororcadeModel.isOperation?1:.6;
    self.repairThirdBtn.alpha=mororcadeModel.isOperation?1:.6;
    self.repairSixBtn.alpha=mororcadeModel.isOperation?1:.6;
    self.repiarFiveBtn.alpha=mororcadeModel.isOperation?1:.6;
    
}
/**
 * 时间分段
 */
-(NSArray *)getPrefixTime:(NSString *)time{
    NSString *prefix=[time substringToIndex:5];
    NSString *suffer=[time substringWithRange:NSMakeRange(prefix.length+1, time.length-prefix.length-1)];
    return @[prefix,suffer];
}
@end
